package com.lanqiao.guimei.commons;

import com.lanqiao.guimei.vo.Category;
import com.lanqiao.guimei.vo.Product;
import com.lanqiao.guimei.vo.Stock;
import com.lanqiao.guimei.vo.Vendor;
import org.apache.commons.dbutils.handlers.AbstractListHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @Author:沈林玉
 * @date:2019/8/18 16:15
 * @Description:
 */
public class ProductListHandler extends AbstractListHandler<Product> {

    @Override
    protected Product handleRow(ResultSet rs) throws SQLException {
        Product product = new Product();
        Category category = new Category();
        Vendor vendor = new Vendor();
        Stock stock = new Stock();
        product.setCategory(category);
        product.setVendor(vendor);
        product.setStock(stock);
/*
* p.prod_no prodNo," +
                "p.ctgr_id ctgrId," +
                "p.ven_id venId," +
                "p.stk_id stkId," +
                "p.CTGR_NAME ctgName," +
                "p.VEN_NAME venName," +
                "p.STK_NAME stkName," +
                "p.prod_name proName," +
                "p.price," +
                "p.type," +
                "p.descr," +
                "p.image" +
* */
//        while (rs.next()) {
            String prodNo = rs.getString("prodNo");
            String ctgName = rs.getString("ctgName");
            String venName = rs.getString("venName");
            String stkName = rs.getString("stkName");
            String proName = rs.getString("proName");
            Double price = rs.getDouble("price");
            Integer quantity = rs.getInt("quantity");
            String type = rs.getString("type");
            String descr = rs.getString("descr");
            String image = rs.getString("image");
            Integer remark = rs.getInt("remark");

            product.setProdNo(prodNo);
            category.setCtgrName(ctgName);
            vendor.setVenName(venName);
            stock.setStkName(stkName);
            stock.setQuantity(quantity);
            product.setProdName(proName);
            product.setPrice(price);
            product.setType(type);
            product.setDescr(descr);
            product.setImage(image);
            product.setRemark(remark);

//        }
        //List<Product> products = (List<Product>)product;
        return product;
    }
}
